package com.igeek.boot.controller;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper;
import com.igeek.boot.entity.User;
import com.igeek.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: zhiyu
 * @Date:10:13
 * @DESC:
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/allUser")
    public List<User> selectUser(){
        List<User> list = userService.list();
        QueryChainWrapper<User> query = userService.query();
        System.out.println("query = " + query.toString());
        List<Map<String, Object>> listMaps = userService.listMaps();
        System.out.println("listMaps = " + listMaps);
        long count = userService.count();
        System.out.println("count = " + count);
        User byId = userService.getById(1);
        System.out.println("byId = " + byId);
        KtQueryChainWrapper<User> userKtQueryChainWrapper = userService.ktQuery();
        System.out.println("userKtQueryChainWrapper = " + userKtQueryChainWrapper.toString());
        return list;
    }
    //通过用户id查询用户信息
    @GetMapping("/{id}")
    public User findOne(@PathVariable("id") int id){
        return userService.getById(id);
    }
}
